<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<html>
<head>
	<base href="<%=basePath%>">
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="common/js/common.js"></script>
</head>
<script type="text/javascript">
	$(function () {
		queryAllDicValueList();
		// 创建
		$("#createDicValueBtn").on("click",function () {
			window.location.href="settings/dictionary/value/createDicValuePage.do";
		})
		// 更新
		$("#editDicValueBtn").on("click",function () {
			// 获取选中复选框的数量
			var checkeds = $("#tBody input:checked");
			// 判断数量
			if (checkeds.length != 1){
				alert("一次只能编辑一条记录！")
				return
			};
			// 获取元素值
			var checkedId = checkeds.val();
			window.location.href="settings/dictionary/value/updateDicValuePage.do?id="+checkedId;
		})
		// 删除
		$("#deleteDicValueBtn").on("click",function () {
			// 获取选中数量
			var checkeds = $("#tBody input:checked");
			if (checkeds.length == 0){
				alert("请选择要删除的数据");
				return
			}
			if (confirm("您真的要删除吗？")){
				// 字符串拼接
				var ids = "";
				$.each(checkeds,function (index,obj) {
					ids += "id="+$(obj).val()+"&";
				});
				ids = ids.substring(0,ids.length-1);
				$.ajax({
					url:"settings/dictionary/type/deleteDicValueById.do",
					type:"post",
					data:ids,
					success:function (data) {
						if (data.code === 1000){
							alert("删除成功！")
							queryAllDicValueList();
						}else {
							alert(data.message);
						}
					}
				});
			}
		});
	});

	function queryAllDicValueList() {
		$.ajax({
			url:"settings/dictionary/type/queryAllDicValueList.do",
			type:"get",
			success:function (data) {
				if (data.code == 1000){
					console.log(JSON.stringify(data))
					var str = "";
					$.each(data.body,function (index,obj) {
						str += "<tr>";
						str += "<td><input type=\"checkbox\" value='"+obj.id+"' /></td>";
						str += "<td>"+(index+1)+"</td>";
						str += "<td>"+obj.value+"</td>";
						str += "<td>"+obj.text+"</td>";
						str += "<td>"+obj.orderNo+"</td>";
						str += "<td>"+obj.typeCode+"</td>";
						str += "</tr>";
					})
					$("#tBody").html(str);
				}else {
					alert(data.message)
				}
			}
		});

	}

</script>
<body>

	<div>
		<div style="position: relative; left: 30px; top: -10px;">
			<div class="page-header">
				<h3>字典值列表</h3>
			</div>
		</div>
	</div>
	<div class="btn-toolbar" role="toolbar" style="background-color: #F7F7F7; height: 50px; position: relative;left: 30px;">
		<div class="btn-group" style="position: relative; top: 18%;">
		  <button id="createDicValueBtn" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> 创建</button>
		  <button id="editDicValueBtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-edit"></span> 编辑</button>
		  <button id="deleteDicValueBtn" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span> 删除</button>
		</div>
	</div>
	<div style="position: relative; left: 30px; top: 20px;">
		<table class="table table-hover">
			<thead>
				<tr style="color: #B3B3B3;">
					<td><input type="checkbox" id="checkedAll"/></td>
					<td>序号</td>
					<td>字典值</td>
					<td>文本</td>
					<td>排序号</td>
					<td>字典类型编码</td>
				</tr>
			</thead>
			<tbody id="tBody">

			</tbody>
		</table>
	</div>

</body>
</html>
